Skip to content

GH-48408: [C++] Enable ULP-based float comparison#49290

Open
andishgar wants to merge 2 commits intoapache:mainfrom
andishgar:enable_ulp_based_comparison
Open

GH-48408: [C++] Enable ULP-based float comparison#49290
andishgar wants to merge 2 commits intoapache:mainfrom
andishgar:enable_ulp_based_comparison

Conversation

@andishgar
Copy link
Contributor

@andishgar andishgar commented Feb 16, 2026

Rationale for this change

Enable ULP-based floating-point comparison.

What changes are included in this PR?

Add arrow::EqualOptions::use_ulp_distance and arrow::EqualOptions::ulp_distance.

Are these changes tested?

Yes.

Are there any user-facing changes?

Yes. The ULP-based comparison method is enabled via arrow::EqualOptions::use_ulp_distance and arrow::EqualOptions::ulp_distance.

@github-actions
Copy link

⚠️ GitHub issue #48408 has been automatically assigned in GitHub to PR creator.

@andishgar andishgar force-pushed the enable_ulp_based_comparison branch from c79f91f to 9cd0147 Compare February 16, 2026 07:40
@andishgar
Copy link
Contributor Author

@pitrou , I would appreciate it if you could review this.

Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this PR @andishgar . As you'll see in the comments below, I think it would be nice to come up with a nicer API for EqualOptions.

bool use_atol_ = false;
bool use_schema_ = true;
bool use_metadata_ = false;
bool use_ulp_distance_ = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a enum to simplify those flags slightly, for example:

  enum FloatComparison { Exact, Atol, Ulps };
  FloatComparison float_comparison_ = Exact;

Alternatively, we could use a std::variant to also encompass the numeric parameters:

  struct ExactComparison {};
  struct UlpComparison { int max_ulps; }
  struct AtolComparison { double atol; }

  // Defaults to ExactComparison
  std::variant<ExactComparison, UlpComparison, AtolComparison> float_comparison_ = {};

auto res = EqualOptions(*this);
res.ulp_distance_ = v;
return res;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is starting to be a lot of methods just to customize FP comparison. Also, usually you know the number of ULPs you want, so you have to call two methods (use_ulp_distance and ulp_distance) which feels pointlessly complicated.

I wonder if we could have a single method to encompass all these usages, for example:

  auto options = EqualOptions().float_comparison(EqualOptions::Atol(1e-5));
  auto options2 = EqualOptions().float_comparison(EqualOptions::Ulps(2));

@github-actions github-actions bot added awaiting review Awaiting review awaiting committer review Awaiting committer review and removed awaiting review Awaiting review awaiting committer review Awaiting committer review labels Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants